GraphQL query implementation for UTCP
The GraphQL provider enables UTCP to interact with GraphQL APIs, allowing for precise data fetching and operations with a flexible query language. GraphQL's type system and query capabilities make it ideal for complex data requirements with minimal network overhead.
GraphQL providers are configured using the following JSON structure:
{ "name": "graphql_api", "provider_type": "graphql", "url": "https://api.example.com/graphql", "operation_type": "query", "operation_name": "GetUserData", "timeout": 30000, "auth": { "auth_type": "api_key", "api_key": "YOUR_API_KEY", "var_name": "Authorization" }, "headers": { "User-Agent": "UTCP Client", "Content-Type": "application/json" }, "header_fields": ["client_version", "trace_id"] }
Field | Required | Description |
---|---|---|
name |
Yes | Unique identifier for the provider |
provider_type |
Yes | Must be set to "graphql" |
url |
Yes | Full URL to the GraphQL endpoint |
operation_type |
No | Type of GraphQL operation: "query" , "mutation" , or "subscription" (default: "query" ) |
operation_name |
No | Name of the GraphQL operation (optional, but recommended) |
timeout |
No | Request timeout in milliseconds (default: 30000 ) |
auth |
No | Authentication configuration (if required) |
headers |
No | Additional HTTP headers to include in the request |
header_fields |
No | List of input fields to be sent as request headers |
GraphQL providers support the same authentication methods as HTTP providers:
{ "auth": { "auth_type": "api_key", "api_key": "YOUR_API_KEY", "var_name": "Authorization" } }
{ "auth": { "auth_type": "bearer", "token": "YOUR_BEARER_TOKEN" } }
{ "auth": { "auth_type": "basic", "username": "your_username", "password": "your_password" } }
GraphQL supports three types of operations:
Read-only operations to fetch data. Most common operation type.
Operations that modify data on the server (create, update, delete).
Real-time operations that listen for data changes over WebSocket.
For GraphQL providers, tool discovery can be done in two ways:
The tool discovery endpoint should be accessible at /utcp
on the same domain:
https://api.example.com/utcp
Tools can be discovered through introspection of the GraphQL schema using the standard introspection query:
query IntrospectionQuery { __schema { queryType { name } mutationType { name } subscriptionType { name } types { ...FullType } } }
{ "name": "user_api", "provider_type": "graphql", "url": "https://api.example.com/graphql", "operation_type": "query", "operation_name": "GetUser", "auth": { "auth_type": "bearer", "token": "YOUR_JWT_TOKEN" } }
{ "name": "product_api", "provider_type": "graphql", "url": "https://api.example.com/graphql", "operation_type": "mutation", "operation_name": "CreateProduct", "timeout": 60000, "auth": { "auth_type": "api_key", "api_key": "YOUR_API_KEY", "var_name": "X-API-Key" } }
{ "name": "notifications_api", "provider_type": "graphql", "url": "wss://api.example.com/graphql", "operation_type": "subscription", "operation_name": "NotificationUpdates", "auth": { "auth_type": "bearer", "token": "YOUR_SUBSCRIPTION_TOKEN" } }
query GetUser($id: ID!) { user(id: $id) { name email role profile { avatar bio } } }
mutation CreateProduct($input: ProductInput!) { createProduct(input: $input) { id name price success errors { field message } } }
subscription OnCommentAdded($postId: ID!) { commentAdded(postId: $postId) { id content author { name } createdAt } }
© 2024 Universal Tool Calling Protocol. All rights reserved.